#include <stdio.h>
#include "genpat.h"

char* inttostr(int entier) {
  char* str;
  str = (char *) mbkalloc (32 * sizeof(char));
  sprintf(str,"%d",entier);
  return(str);
}

main() {
  int i;
  
  DEF_GENPAT("test_data_memory");

  DECLAR("CLK_i"             ,":2","B", IN   ,	""         , "");
  DECLAR("DATA_i"		     ,":2","B", IN   ,"3  downto 0", "");
  DECLAR("WRITE_ENABLE_i"    ,":2","B", IN   ,	""         , "");
  DECLAR("ADDRESS_i"       	 ,":2","B", IN   ,"5  downto 0", "");
  DECLAR("COUNTER_i"       	 ,":2","B", IN   ,"1  downto 0", "");
  DECLAR("DATA_o"       	 ,":2","B", OUT  ,"3  downto 0", "");
  DECLAR("vdd"           	 ,":2","B", IN   ,	""         , "");
  DECLAR("vss"            	 ,":2","B", IN   ,	""         , "");

  LABEL("data_memory");
  
  SETTUNIT("ns");
  AFFECT("0"    , "vdd"	            , "1"); 
  AFFECT("0"    , "vss"	            , "0");
  AFFECT("0"    , "DATA_i" 	        , "1");
  AFFECT("0"    , "WRITE_ENABLE_i"  , "1");
  AFFECT("0"    , "CLK_i"           , "0");
  AFFECT("0"    , "ADDRESS_i"	    , "0");
  AFFECT("0"    , "COUNTER_i"	    , "0");
 
  for(i=0; i<24; i++) {
    AFFECT("+50","CLK_i"	        , inttostr(i%2));
    /*AFFECT("0"    , "DATA_I"      , inttostr(i%2));
    if(i==2){
	AFFECT("+0"	, "VECTOR_ELEMENT_ENABLE"		    , "0");
	AFFECT("+0"	, "WRITE_ENABLE"		    , "1");
    }*/
    if(i==8){
	AFFECT("+0"	,"ADDRESS_i"        , "4");
	AFFECT("+0" ,"DATA_i" 	        , "0");
    }
    if(i==8){
	AFFECT("+0"	,"WRITE_ENABLE_i"   , "0");
	AFFECT("+0" ,"ADDRESS_i"	    , "100000");
    }
    if(i==9){
	AFFECT("+0" ,"DATA_i"           , "2");
    }
    if(i==12){
	AFFECT("+0"	,"WRITE_ENABLE_i"   , "1");
    }
    if(i==16){
	AFFECT("+0"	,"WRITE_ENABLE_i"   , "0");
    }
    if(i==20){
	AFFECT("+0" ,"ADDRESS_i"	    , "0");
    }
  }
  SAV_GENPAT();

  exit(0);
}
